﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GtsServer.Service.Model;
using GtsServer.DAL;
using GtsServer.Model;
using GtsServer.Service.Model.Request;
using Pub.Class;
using GtsServer.Common;

namespace GtsServer.Charge.Page
{
    public class ZhiFuBaoCallBack : System.Web.UI.Page
    {
        OrderDAL orderDAL = new OrderDAL();
        GtsServer.DAL.PrizeTaskReocrdDAL prizetaskreocrdDAL = new DAL.PrizeTaskReocrdDAL();
        public string json = string.Empty;

        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            LogHelper.WriteLog("dasdas");
            OrderDAL orderDAL = new OrderDAL();
            GtsServer.DAL.PrizeTaskReocrdDAL prizetaskreocrdDAL = new DAL.PrizeTaskReocrdDAL();
            string json = string.Empty;
            json = Request2.GetRequestInputStream().UrlDecode();
            LogHelper.WriteLog(json);

            string orderID = Request.Form["out_trade_no"];// GetTypeName("out_trade_no").ToStr();
         
            // GetTypeName("trade_status") == "TRADE_FINISHED" ? Convert.ToInt32(OrderStutas.成功) : Convert.ToInt32(OrderStutas.不成功);
            int status = Request.Form["trade_status"] == "TRADE_FINISHED" ? Convert.ToInt32(OrderStutas.成功) : Convert.ToInt32(OrderStutas.不成功); 

            if (!string.IsNullOrEmpty(orderID))
                orderDAL.UpdateOrderStutas(orderID, status);
        }

        public string GetTypeName(string type)
        {
            return (json.GetMatchingValues("<" + type + ">(.+?)</" + type + ">", "<" + type + ">", "</" + type + ">").FirstOrDefault() ?? "").Trim();
        }

    }
}
